package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RedAffairMapper;
import com.ruoyi.system.domain.RedAffair;
import com.ruoyi.system.service.IRedAffairService;

/**
 * 红事Service业务层处理
 *
 * @author ruoyi
 * @date 2022-04-25
 */
@Service
public class RedAffairServiceImpl implements IRedAffairService {
    @Autowired
    private RedAffairMapper redAffairMapper;

    /**
     * 查询红事
     *
     * @param id 红事主键
     * @return 红事
     */
    @Override
    public RedAffair selectRedAffairById(String id) {
        return redAffairMapper.selectRedAffairById(id);
    }

    /**
     * 查询红事列表
     *
     * @param redAffair 红事
     * @return 红事
     */
    @Override
    @DataScope(deptAlias = "r")
    public List<RedAffair> selectRedAffairList(RedAffair redAffair, String begin, String end) {
        Date begin1 = null, end1 = null;
        if (StringUtils.isNotEmpty(begin) && StringUtils.isNotEmpty(end)) {
            begin1 = new Date(Long.parseLong(String.valueOf(begin)));
            end1 = new Date(Long.parseLong(String.valueOf(end)));
            redAffair.setBeginDate(begin1);
            redAffair.setEndDate(end1);
        }
        return redAffairMapper.selectRedAffairList(redAffair);
    }

    /**
     * 新增红事
     *
     * @param redAffair 红事
     * @return 结果
     */
    @Override
    public int insertRedAffair(RedAffair redAffair) {
        if (StringUtils.isNotEmpty(redAffair.getAffairTime())) {
            String d1 = redAffair.getAffairTime().split("至")[0];
            if (StringUtils.isNotEmpty(d1)) {
                redAffair.setBeginDate(DateUtils.StrToDate(d1));
            }
            String d2 = redAffair.getAffairTime().split("至")[1];
            if (StringUtils.isNotEmpty(d1)) {
                redAffair.setEndDate(DateUtils.StrToDate(d2));
            }

        }
        return redAffairMapper.insertRedAffair(redAffair);
    }

    /**
     * 修改红事
     *
     * @param redAffair 红事
     * @return 结果
     */
    @Override
    public int updateRedAffair(RedAffair redAffair) {
        return redAffairMapper.updateRedAffair(redAffair);
    }

    /**
     * 批量删除红事
     *
     * @param ids 需要删除的红事主键
     * @return 结果
     */
    @Override
    public int deleteRedAffairByIds(String[] ids) {
        return redAffairMapper.deleteRedAffairByIds(ids);
    }

    /**
     * 删除红事信息
     *
     * @param id 红事主键
     * @return 结果
     */
    @Override
    public int deleteRedAffairById(String id) {
        return redAffairMapper.deleteRedAffairById(id);
    }
}
